<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC1117 – Backslash is literal in `"\n"`. Prefer explicit escaping: `"\\n"`.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC1117 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC1117">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2 id="backslash-is-literal-in-n-prefer-explicit-escaping-n">Backslash
is literal in <code>"\n"</code>. Prefer explicit escaping:
<code>"\\n"</code>.</h2>
<p><strong>Note: this warning has been retired due to being too
pedantic</strong></p>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC1117.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="bu">printf</span> <span class="st">&quot;%s\n&quot;</span> <span class="st">&quot;Hello&quot;</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC1117.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">printf</span> <span class="st">&quot;%s</span><span class="dt">\\</span><span class="st">n&quot;</span> <span class="st">&quot;Hello&quot;</span></span></code></pre></div>
<p>or alternatively, with single quotes:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="SC1117.html#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="bu">printf</span> <span class="st">&#39;%s\n&#39;</span> <span class="st">&quot;Hello&quot;</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>In a double quoted string, you have escaped a character that has no
special behavior when escaped. Instead, it's invoking the fallback
behavior of being interpreted literally.</p>
<p>Instead of relying on this implicit fallback, you should escape the
backslash explicitly. This makes it clear that it's meant to be passed
as a literal backslash in the string parameter.</p>
<h3 id="exceptions">Exceptions:</h3>
<p>None. This is a stylistic issue which can be <a
href="ignored.html">ignored</a>. But can you name the 5 characters that
<em>are</em> special when escaped in double quotes?</p>
<p>They are $, `, ", \, or newline. More infos are available in the <a
href="https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html">bash
manual</a>.</p>
<h3 id="retired">Retired:</h3>
<p>This warning is no longer emitted as of d8a32da07 (strictly after
v0.5).</p>
<p>The number of harmlessly affected <code>printf</code>,
<code>sed</code> and <code>grep</code> statements was significantly
higher than the number of actual unexpanded escape sequences. It may
return some day under a <code>-pedantic</code> type flag.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


